﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace UpLoadPSDataSystem.Util
{
    public class Helper
    {

       
        private static List<int> _ports;
 
        private static Dictionary<int, string> _mappings;
        public static Dictionary<int, string> Mappings()
        {
            if (_mappings == null)
            {
                _mappings = new Dictionary<int, string>();
                var skpwConnection = new SqlConnection(Properties.Settings.Default.SKPW_ConnectionString);
                var skpwCommand = new SqlCommand
                {
                    Connection = skpwConnection,
                    CommandType = CommandType.Text
                };
                string sqlString = "select Let_Port_ID,XPSName,LastMaxID from Envi_UploadXPSDataMapping";
                skpwCommand.CommandText = sqlString;
                if (skpwConnection.State == ConnectionState.Closed)
                    skpwConnection.Open();
                DataTable allDt = new DataTable();
                var xpsSda = new SqlDataAdapter(skpwCommand);
                xpsSda.Fill(allDt);
                foreach (DataRow row in allDt.Rows)
                {
                    try
                    {
                        _mappings.Add(int.Parse(row["Let_Port_ID"].ToString()), row["XPSName"].ToString());
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }
            return _mappings;
        }

     
    }
}
